﻿@{
    Layout = null;
    var patch = ViewBag.patch;
    var enterId = ViewBag.enterId;
    var batchId = ViewBag.batchId;
    var eName = ViewBag.eName;
}
@*导码*@
@*<script src="~/Scripts/WebUploader/webuploader.js"></script>*@

<style>
    .myTabs.nav-tabs > li.active > a, .myTabs.nav-tabs > li.active > a:focus, .myTabs.nav-tabs > li.active > a:hover {
        color: #555;
        cursor: default;
        background-color: #fff;
        border: 1px solid #ddd;
        border-bottom-color: transparent;
    }

    #picker input[type="file"] {
        opacity: 0;
    }

    .form-group .form-control p {
        margin: 0;
    }
</style>
<form id="LeadOut_form" onkeydown="if(event.keyCode==13){return false;}">
    <div class="mtlr15">


        <div class="form-group" style="display:flex;margin-top:30px;">
            <label id="picker" class="btn btn-success">选择文件</label>
            <div class="form-control"></div>
        </div>
        <div class="form-group" style="display:flex;margin-top:30px;">
            <label class="btn btn-success">是否激活</label>
            <div class="form-control">
                <input id="yradio" type="radio" name="Flag" value="1" />
                <label for="yradio"> 是</label>
                <input id="fradio" type="radio" name="Flag" value="0" />
                <label for="fradio"> 否 </label>

            </div>
        </div>
    </div>
</form>
<script>
    $(function () {
        var uploader = WebUploader.create({

            // swf文件路径
            //swf: BASE_URL + '/js/Uploader.swf',
            // 文件接收服务端。
            server: '/CodeManage/leadCodeSave',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id: '#picker',
                multiple: false
            },
            accept: {
                title: '文本',
                extensions: 'txt',
                mimeTypes: '*.txt'
            },
            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false
        });

        // 当有文件被添加进队列的时候
        uploader.on('fileQueued', function (file) {
            $('#picker').next().append('<div id="' + file.id + '" >' +
                '<span class="info">' + file.name + '</span>' +
                '<p class="state">等待上传...</p>' +
            '</div>');
            $('#picker').attr('disabled', 'disabled');
            $('#picker input[type="file"]').attr('disabled', 'disabled');
        });
        // 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                  '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                  '</div>' +
                '</div>').appendTo($li).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css('width', percentage * 100 + '%');
        });
        uploader.on('uploadSuccess', function (file, r) {
            $('#' + file.id).find('p.state').text('已上传');
            //跳转页面
            if (r > 0) {
                $.MGJ.LeadCode.Dialog_LeadOutObj.close();
                $.L.msgWarning("上传成功！");
            } else {
                $.L.msgWarning("上传失败！");
            }
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('p.state').text('上传出错');
        });

        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').fadeOut();
        });
        $('button[data-btnname="button_save"]').click(function () {
            uploader.options.formData = { Flag: $("input[type='radio'][name='Flag']:checked").val(), enterId: "@enterId", patch: "@patch", batchId: "@batchId",eName:"@eName" };
            uploader.upload();
          

        })
   


    });


</script>

